package cn.tedu._04interceptor.base.config;

import cn.tedu._04interceptor.base.interceptors.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
 * 拦截器配置类
 */
@Configuration//有这个注解，在项目启动的时候会优先去扫描配置类
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor())
                //拦截多个请求路径
                //.addPathPatterns("/v1/user/login\",\"/v1/user/reg\",\"/v1/user/change");
                //拦截所有请求路径
                .addPathPatterns("/v1/user/**")
                //排除拦截的请求路径(出了登录不拦截，其他的都拦截)
                .excludePathPatterns("/v1/user/login");
    }
}
